package com.qf.sy2103.springboot.Configuration;

import com.qf.sy2103.springboot.Filter.HandlerFilter;
import com.qf.sy2103.springboot.Util.Myintercept;
import lombok.experimental.SuperBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.FilterRegistration;


//这个类可以配置拦截器、过滤器、以及监听器
@Configuration
public class MyWebConfiguration implements WebMvcConfigurer {

    //配置拦截器拦截的路径
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new Myintercept()).
                addPathPatterns("/index.html","/views/*.html");
    }


//    @SuppressWarnings({ "rawtypes", "unchecked" }) 这个是忽略警告注解
    @Bean
    //配置过滤器
    public FilterRegistrationBean filterRegist(){
        FilterRegistrationBean frBean = new FilterRegistrationBean();
        frBean.setFilter(new HandlerFilter());
        frBean.addUrlPatterns("/*");
        System.out.println("filter");
        return frBean;
    }
}
